﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


public class StringUtils
{
    /// <summary>
    /// 修正字符串name，确保其不在列表list中。
    /// 修正的方式为在其后添加确保与list不重名的最小自然数
    /// </summary>
    /// <param name="list"></param>
    /// <param name="name"></param>
    /// <returns></returns>
    static public string GetVoidName(List<string> list, string name)
    {
        int idx = list.IndexOf(name);
        while (idx >= 0)
        {
            int i = name.Length - 1;
            while (i >= 0 && name[i] >= '0' && name[i] <= '9') i--;
            if (i < 0 || i + 1 >= name.Length)
                name += "1";
            else
            {
                int no = int.Parse(name.Substring(i + 1));
                name = name.Substring(0,i+1) + (no + 1);
            }
            idx = list.IndexOf(name);
        }
        return name;
    }
}
